<div style="padding: 15px;">
<a class="layui-btn"  href="/admin/category/addCateGory">添加分类</a>

<div id="table" style="width:100%"></div>
</div>

<script type="text/html" id="bar">

  <a class="layui-btn layui-btn-xs"  lay-event="edit">编辑</a>
 <a class="layui-btn layui-btn-danger layui-btn-xs"   lay-event="del">删除</a>
</script>

<script>
  
layui.use('table', function(){
  table = layui.table;

  tableobj = table.render({
    elem: '#table'
    ,url:'/admin/category/getInfo'
   
    ,cols: [[
     // {field:'update_time', title: '更新时间',unresize:true}
      {field:'id',width:100, type:'normal', title: 'ID', }
      ,{field:'category_name',width:150,title: '分类名称'}
     
 ,{field:'create_time',width:170,  title: '创建时间'}

     ,{field:'update_time', width:170, title: '更新时间'}
      ,{field:'active', title: '操作',toolbar: '#bar'}
    ]]


    ,page:{
    	layout:['prev','page','next','count','skip'],
    	prev:'上一页',
    	next:'下一页',
    	limit:5,

    }

     ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
     	
     	return {
     		"code":res.code,
     		"count": res.total,

    		"data": res.CateGory //解析数据列表
     	}

    }
  });
   table.on('tool()', function(obj){
    var data = obj.data;
  	if(obj.event === 'edit'){

      window.location.href = "/admin/category/edit/"+data.id;
    }
    if(obj.event === 'del'){

     layui.use('layer', function(){
     var layer = layui.layer;
       layer.confirm('确定要删除', {
        btn: ['确定', '取消'] //可以无限个按钮
       
      }, function(index, layero){
         $.get('/admin/category/del/'+data.id,function(res){
        
        window.location.href = "/admin/category"
      })
      }, function(index){
        return;
      });
  })
      
    }
  });

});

</script>
</div>